package com.example.news.dao;

import android.util.Log;

import com.example.news.entity.History;
import com.google.gson.Gson;

import java.util.List;

/**
 * @author Admin
 */
public class HistoryDao extends History {

    public static List<History> queryHistory(String userName) {
        return History.find(History.class, "user_name=?", new String[]{userName});
    }

    //    String uniquekey = dataDTO.getUniquekey();
//    long count = History.count(History.class, "uniquekey=? and user_name=?", new String[]{uniquekey, userinfo.getUserName()});
//        Log.d(TAG, "onCreate: uniquekey "+ uniquekey+" count " + count);
//        if(count==0){
//        long save = History.save(new History(uniquekey, userinfo.getUserName(), new Gson().toJson(dataDTO)));
//        Log.d(TAG, "onCreate: save " + save);
//    }
    public static boolean queryHasSave(String uniquekey, String userName) {
        long count = History.count(History.class, "uniquekey=? and user_name=?", new String[]{uniquekey, userName});
        return count == 0;
    }

    public static long saveHistory(String uniquekey, String userName, String jsonContent) {
        long save = History.save(new History(uniquekey, userName, jsonContent));
        return save;
    }
}
